﻿using System;
using System.ComponentModel.Composition;
using Cubicle.Core.Interfaces;
using Cubicle.Core.Processors;

namespace Cubicle.Excel.Processors
{
    [Export("Cubicle.Excel.Processors.MarshalSByte", typeof(IProcessor<object>))]
    [ExportMetadata("Name", "MarshalSByte")]
    [ExportMetadata("Description", "Casts SByte to Int32.")]
    public class MarshalSByte : ConditionalProcessor<object>
    {
        #region Overrides of Processor<InstructionRequest>

        private readonly Type _sbyteType = typeof (SByte);

        public override bool Condition(object request)
        {
            return request.GetType() == _sbyteType;
        }

        public override object ConditionalProcess(object request)
        {
            return Convert.ToInt32(request);
        }

        #endregion
    }
}